package cn.com.generaldata.os.job;

import java.text.ParseException;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class AutoCallWebServiceScheduler {
	private static final String WEBSERVICE_AUTO_CALL = "webserviceAutoCall";
	private static Scheduler scheduler = null;

	public void init() throws SchedulerException, ParseException {
		SchedulerFactory factory = new StdSchedulerFactory();
		if (scheduler == null) {
			scheduler = factory.getScheduler();
			scheduler.start();
			scheduleJob();
		}
	}

	private void scheduleJob() throws ParseException, SchedulerException {
		JobDetail jobDetail = new JobDetail("job_call_webservice", WEBSERVICE_AUTO_CALL, AutoCallWebServiceJob.class);
		// JobDataMap map = jobDetail.getJobDataMap();
		// map.put("userIds", rule.getUserIds());
		// map.put("billboardTitle", rule.getBillboardTitle());
		// map.put("billboardContent", rule.getBillboardContent());
		// map.put("operator", rule.getOperator());

		CronTrigger trigger = new CronTrigger("trigger_call_webservice", WEBSERVICE_AUTO_CALL, "0 0 0 1 * ?");
		scheduler.scheduleJob(jobDetail, trigger);
	}

	public void destroy() throws SchedulerException {
		if (scheduler != null) {
			scheduler.shutdown();
		}
	}
}
